package com.jxj.study.util;

import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
import org.springframework.util.ResourceUtils;
import java.io.OutputStream;
public class PdfUtil {
    public static void buildPdf(OutputStream os, String htmlContent) throws Exception {
        PdfRendererBuilder builder = new PdfRendererBuilder();
        builder.useFont(ResourceUtils.getFile("classpath:templates/fonts/SimHei.ttf"), "simhei");
        builder.useFastMode();
        builder.withHtmlContent(htmlContent, ResourceUtils.getURL("classpath:templates/img").getPath());
        builder.toStream(os);
        builder.run();
    }
}